package com.hh.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hh.pojo.Total;
import com.hh.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Controller
public class TotalController {
    @Autowired
    private TotalService totalService;
    //根据温湿度传感器查询
    @GetMapping("/queryTemp")
    public String queryTemp(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum ,String sensorType) {
        PageHelper.startPage(pageNum, 5);//设置页面的位置和展示的数据条目数
        List<Total> list = totalService.queryTemp();
        PageInfo<Total> pageInfo = new PageInfo<>(list);//PageInfo用来封装页面信息，返回给前台界面
        model.addAttribute("pageInfo", pageInfo);
        return "queryTemp";
    }
    //根据光照度传感器查询
    @GetMapping("/queryLight")
    public String queryLight(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum ,String sensorType) {
        PageHelper.startPage(pageNum, 5);//设置页面的位置和展示的数据条目数
        List<Total> list = totalService.queryLight();
        PageInfo<Total> pageInfo = new PageInfo<>(list);//PageInfo用来封装页面信息，返回给前台界面
        model.addAttribute("pageInfo", pageInfo);
        return "queryLight";
    }
    //查询整张表
    @GetMapping("/queryAll")
    public String queryAll(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum) {
        PageHelper.startPage(pageNum, 5);//设置页面的位置和展示的数据条目数
        List<Total> list = totalService.queryAll();
        PageInfo<Total> pageInfo = new PageInfo<>(list);//PageInfo用来封装页面信息，返回给前台界面
        model.addAttribute("pageInfo", pageInfo);
        return "dateView";
    }
}
